﻿using Microsoft.AspNetCore.Mvc;

namespace _11Net8AspNetCore_WebApis.Controller
{
    [ApiController]
    //[Route("api/[controller]")]
    ///1.1、路由模板 [Route("地址")]  分为固定和变量
    [Route("api/[controller]/Actions")]
    public class RouterController
    {
        #region  路由参数
        /// <summary>
        /// 1.2.1\单路由参数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public string GetRoute(string id)
        {
            return "成功";
        }

        /// <summary>
        /// 1.2.2、多路由参数
        /// </summary>
        /// <param name="id"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        [HttpGet("Age1/{id}/{age}")]
        public string GetAge1(string id, int age)
        {
            return "成功";
        }

        /// <summary>
        /// 1.2.3、路由约束 练习没有发现有什么用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        [HttpGet("{id:int}/{age}")]
        public string GetAge2(int id, int age)
        {
            return "成功";
        }

        /// <summary>
        /// 1.2.4\路由默认值 从后面向前进行默认
        /// </summary>
        /// <param name="id"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        [HttpGet("{id1}/{age1=-1}")]
        public string GetAge3(int id1, int age1)
        {
            return "成功";
        }

        /// <summary>
        /// 1.2.5\自定义路由
        /// </summary>
        /// <param name="id"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("action/{id}/{age}")]
        public string GetAge4(string id, int age)
        {
            return "成功";
        }
        ///总结：
        /// 路径变量：路由在路径中的变量
        /// 含义：路径中 变量 大括号{} 可以传递值
        /// 好处：方便设置restful风格的webApi规格接口
    #endregion

}
}
